package org.nf.shopping.controller;

import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;

import org.nf.shopping.common.vo.ResultVO;
import org.nf.shopping.entity.Role;
import org.nf.shopping.service.RoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author czl
 * @Date 2024-12-02
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/role")
public class RoleController extends BaseController{
    private final RoleService roleService;
    @GetMapping("/getRoleListByPage")
    public ResultVO<PageInfo<Role>> getRoleListByPage(Integer limit, Integer page, String adminName, String adminType){
        PageInfo<Role> pageInfo = roleService.getRoleListByPage(limit, page,adminName,adminType);
        return success(pageInfo);
    }

    @PostMapping("/checkPwd")
    public void checkPwd(String pwd,String userName,String newPwd){
        roleService.checkPwd(pwd, userName, newPwd);
    }

    @GetMapping("/listRole")
    public ResultVO<PageInfo<Role>> listAdmin(Integer limit, Integer page, String name){
        PageInfo<Role> pageInfo = roleService.listRole(limit, page, name);
        return success(pageInfo);
    }

    @PostMapping("/updateRole")
    public ResultVO updateAdmin(Role role){
        roleService.updateRole(role);
        return success();
    }

    @PostMapping("/deloneRole")
    public ResultVO deloneAdmin(Integer id){
        roleService.deloneRole(id);
        return success();
    }

    @PostMapping("/addRole")
    public ResultVO addAdmin(Role role){
        roleService.addRole(role);
        return success();
    }

    @PostMapping("/getRoleList")
    public ResultVO<List<Role>> getAdminList(){
        return success(roleService.getRoleList());
    }
}
